<%@page contentType="text/html" pageEncoding="windows-1252"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.util.ArrayList"%>
<%@page import="startup.model.user.exception.NoDataForSettedInputException"%>
<%@page import="startup.model.user.Manager"%>
<%@page import="startup.model.user.Professor"%>
<%
	try
	{
		Manager manager = new Manager();

		Professor professor = ( Professor )session.getAttribute( "currentSessionUser" );

		professor.showRoles( professor.getId() );
		professor.nameOfAdmin();

		ResultSet resultStudent;
		ResultSet resultParziale;
		Integer are_personal_funds_used, has_coord_approved;

		String id = String.valueOf( professor.getId() );

		manager.showStudent( id );
		resultStudent = manager.getResultToServlet();
		resultStudent.beforeFirst();

%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="windows-1252">
		<title>Manager</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="description" content="">
		<meta name="author" content="">
		<!-- Le styles -->
		<link href="styles/bootstrap.css" rel="stylesheet">
		<style type="text/css">
			body {
				padding-top: 60px;
				padding-bottom: 40px;
			}
			.sidebar-nav {
				padding: 9px 0;
			}
		</style>
	</head>
	<body>
        <!--Barra Superiore --> 
        <div class="navbar navbar-fixed-top">
			<div class="navbar-inner">
				<div class="container-fluid">
					<a class="brand" href="#">Manager : <%= professor.getSurname() %> <%= professor.getName() %></a>
					<div class="nav pull-right">
						<ul class="nav">
							<li>
								<form action="Logout" method="post">
									<button class="btn btn-primary btn-small">Sign out</button>
								</form>
							</li>
						</ul>
					</div>
				</div>
			</div>
        </div>
		<!--CONTENUTO LISTE -->
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span3" style="position:fixed;">
					<div class="well sidebar-nav">
						<ul class="nav nav-list"> 
							<li><a href="javascript:history.back()"><i class="icon-arrow-left"></i> Back</a></li>
							<li class="nav-header">Location</li>
							<li><a href="professorHome.jsp"><i class="icon-home"></i> Home</a></li>
							<li class="nav-header">Roles</li>
							<%
								if( professor.isCoordinator() == true )
								{
							%>
							<li><a href="coordinatorShowTrips.jsp"><i class="icon-user"></i> Coordinator</a></li>
							<%										}
								if( professor.isManager() == true )
								{
							%>
							<li class="active"><a href="#"><i class="icon-white icon-user"></i> Manager</a></li>
							<%										}
								if( professor.isSupervisor() == true )
								{
							%>
							<li><a href="supervisorShowTrips.jsp"><i class="icon-user"></i> Supervisor</a></li>
							<%										}
							%>
							<li class="nav-header">Function</li>
							<li><a href="professorFAQ.jsp"><i class="icon-info-sign"></i> F.A.Q.</a></li>
						</ul>
					</div><!--/.well -->
				</div><!--/span-->
				<div class="span9" style="margin-left: 26%;">
					<div class="row-fluid">
						<div class="hero-unit">
							<h1>Trips to approve</h1>
						</div>
					</div>
					<div class="row-fluid">
						<div>
							<%
								if( !resultStudent.next() )
								{
							%>
							<div class="alert alert-warning">
								<button class="close" data-dismiss="alert">x</button>
								<h3> There is nothing to do here.</h3><br />
								<p>
									There are not trips to approve.
								</p>
							</div>        
							<%										}
							else
							{

								resultStudent.beforeFirst();
								resultStudent.next();

								Integer indice = 0;
								Integer elemento = 0;
								do
								{
									are_personal_funds_used = resultStudent.getInt( "are_personal_funds_used" );
									has_coord_approved = resultStudent.getInt( "has_coord_approved" );

									int trip_ID = resultStudent.getInt( "trip_ID" );
									int student = resultStudent.getInt( "student" );

									manager.getStudentName( student );
									resultParziale = manager.getResultToServlet();

									String last_name = resultParziale.getString( "last_name" );
									String first_name = resultParziale.getString( "first_name" );

									if( resultStudent.getInt( "alternative_fund_1_manager" ) == professor.getId() && !resultStudent.getBoolean( "has_fund_1_mgr_approved" ) ||
										resultStudent.getInt( "alternative_fund_2_manager" ) == professor.getId() && !resultStudent.getBoolean( "has_fund_2_mgr_approved" ) )
									{
										if( elemento % 4 == 0 )
										{
							%>
							<div class="row-fluid">
								<%							}
									elemento++;
								%>
								<div class="span3">
									<div class="thumbnail">
										<form action="estimate_prof.jsp" method="post">
											<button class="thumbnail-bottone" style="height: 320px; width: 100%;">
												<strong><%=resultParziale.getString( "last_name" )%> <%=resultParziale.getString( "first_name" )%></strong>
												<input name="IdPreventive" type="hidden" value="<%=trip_ID%>" />
												<br/><br/>
												<img class="pagination-centered" src="http://placehold.it/100x150">
												<br /><br/>                                                    
												<div class="well">
													<%=resultStudent.getString( "Planned_destination" )%>                                                                           
													<br /><br />
													<strong><%=resultStudent.getString( "Planned_Reason_for_Travel" )%></strong>
												</div> 
											</button>
										</form>
										<a class="btn btn-success" data-toggle="modal"  href="#AcceptModal<%=indice%>" style="margin-top: 6px;"><i class="icon-thumbs-up icon-white"></i> Accept</a> 
										<a class="btn btn-danger" data-toggle="modal" href="#RefuseModal<%=indice%>" style="margin-top: 6px;"><i class="icon-trash icon-white"></i> Refuse</a>
										<!--MODAL che appare quando si clicca su Accept-->
										<div class="modal hide fade" id="AcceptModal<%=indice%>">
											<div class="modal-header">
												<button class="close" data-dismiss="modal">x</button>
												<h3>Are You Sure?</h3>
											</div>
											<div class="modal-body">
												<p>Click "Save Changes" to ACCEPT the trip <%=trip_ID%>, Close instead.</p>
											</div>
											<div class="modal-footer">
												<table>
													<tr>                                                    
														<td>
															<form action="ManagerModify" method="post">
																<input name="trip_id" type="hidden" value="<%=trip_ID%>"/>
																<input name="approvato" type="hidden" value="1"/>
																<button class="btn btn-primary btn-success"><i class="icon-thumbs-up icon-white"></i> Save Changes</button>
															</form>
														</td>
														<td>
															<button class="btn" data-dismiss="modal">Close</button>
														</td>
													</tr>
												</table>
											</div>
										</div>                                            
										<!--MODAL che appare quando si clicca su Refuse-->
										<div class="modal hide fade" id="RefuseModal<%=indice%>">
											<div class="modal-header">
												<button class="close" data-dismiss="modal">x</button>
												<h3>Are You Sure?</h3>
											</div>
											<div class="modal-body">
												<p>Click "Save Changes" to REFUSE the trip <%=trip_ID%>, Close instead.</p>
											</div>
											<div class="modal-footer">
												<form action="ManagerModify" method="post">
													<textarea name="noteRefuse"></textarea><br />
													<table>
														<tr>                                                    
															<td>
																<input name="trip_id" type="hidden" value="<%=trip_ID%>"/>
																<input name="approvato" type="hidden" value="0"/>
																<button class="btn btn-primary btn-danger"><i class="icon-trash icon-white"></i> Save Changes</button>
															</td>
															<td>
																<button class="btn" data-dismiss="modal">Close</button>
															</td>
														</tr>
													</table>
												</form>
											</div>
										</div>
									</div>
								</div>
								<%}
									if( elemento == 4 )
									{
										elemento = 0;
								%>
							</div>
							<br />
							<br />
							<%
										}
										indice++;

									}
									while( resultStudent.next() );
								}
							%>
						</div>
					</div>
				</div>
			</div>
        </div><!--/.fluid-container-->
        <div class="navbarCC navbar-fixed-bottom">
            <div class="navbarCC-inner">
                <div class="container-fluid">				
                    <a class="brand" href="#">&copy; 2012 Startup</a>					
                </div>
            </div>
        </div>
		<!-- Il javascript -->
		<script src="js/jquery.js"></script>
		<script src="js/bootstrap.js"></script>
	</body>
</html>
<%
	}
	catch( SQLException sqlException )
	{
		sqlException = new SQLException( "The database is currently busy.<br />" +
										 "If the problem persists, please report it to the administration." );
		request.setAttribute( "exception", sqlException );
		request.getRequestDispatcher( "errorPage.jsp" ).forward( request, response );
	}
	catch( RuntimeException runtimeException )
	{
		if( runtimeException.getClass().equals( NullPointerException.class ) )
		{
			runtimeException = new NullPointerException( "The session has timed out:<br />" + "" +
														 "try reloading page.<br />" +
														 "If the problem persists, please report it to the administration." );
		}
		request.setAttribute( "exception", runtimeException );
		request.getRequestDispatcher( "errorPage.jsp" ).forward( request, response );
	}
%>